package com.imut.lagain.repository;
import org.slf4j.LoggerFactory;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.imut.lagain.entity.CarePreference;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 关怀偏好数据访问层
 */
@Mapper
public interface CarePreferenceRepository extends BaseMapper<CarePreference> {

    /**
     * 根据用户ID查询关怀偏好
     * @param userId 用户ID
     * @return 关怀偏好列表
     */
    @Select("SELECT * FROM care_preference WHERE user_id = #{userId} AND is_deleted = 0")
    List<CarePreference> findByUserId(@Param("userId") Long userId);

    /**
     * 根据用户ID和关怀类型查询偏好
     * @param userId 用户ID
     * @param careType 关怀类型
     * @return 关怀偏好
     */
    @Select("SELECT * FROM care_preference WHERE user_id = #{userId} AND care_type = #{careType} AND is_deleted = 0")
    CarePreference findByUserIdAndCareType(@Param("userId") Long userId, @Param("careType") String careType);

    /**
     * 查询启用的关怀偏好
     * @param userId 用户ID
     * @return 启用的关怀偏好列表
     */
    @Select("SELECT * FROM care_preference WHERE user_id = #{userId} AND enabled = 1 AND is_deleted = 0")
    List<CarePreference> findEnabledByUserId(@Param("userId") Long userId);

    /**
     * 根据关怀类型和频率查询偏好
     * @param userId 用户ID
     * @param careType 关怀类型
     * @param frequency 频率
     * @return 关怀偏好列表
     */
    @Select("SELECT * FROM care_preference WHERE user_id = #{userId} AND care_type = #{careType} AND frequency = #{frequency} AND enabled = 1 AND is_deleted = 0")
    List<CarePreference> findByUserIdAndCareTypeAndFrequency(
            @Param("userId") Long userId, 
            @Param("careType") String careType, 
            @Param("frequency") String frequency);
}
